//
//  EmotionModel.m
//  SinaWebo
//
//  Created by wwj on 16/5/16.
//  Copyright © 2016年 亦心. All rights reserved.
//

#import "EmotionModel.h"
#import <MJExtension.h>

@implementation EmotionModel
MJCodingImplementation

+ (NSDictionary *)replacedKeyFromPropertyName{
    return @{@"ID" : @"id"};
}

- (NSString *)emtionStr{
    if (self.code) {
        NSNumber *number = [self numberWithString:self.code];
        UTF32Char char32 = number.unsignedIntValue;
        NSString *str = [[NSString alloc] initWithBytes:&char32 length:4 encoding:NSUTF32LittleEndianStringEncoding];
        return str;
    }
    return nil;
    
}

- (NSNumber *)numberWithString:(NSString *)str{
    NSScanner *scan = [NSScanner scannerWithString:str];
    int sign = 0;
    if ([str hasPrefix:@"0x"]){
        sign = 1;
    }else if ([str hasPrefix:@"-0x"]) {
        sign = -1;
    }
    unsigned num = -1;
    BOOL suc = [scan scanHexInt:&num];
    if (suc){
        return [NSNumber numberWithLong:((long)num * sign)];
    }
    return nil;
}

+ (instancetype)emotionModle:(BOOL)flag{
    EmotionModel *modle = [[EmotionModel alloc] init];
    modle.isDelete = flag;
    return modle;
}

@end
